const Controller = require('egg').Controller;

class AddressController extends Controller {
    async login() {
        const {ctx,app} = this;
        try{
            const data = await ctx.service.user.login()
            if(typeof data == 'string') {
                ctx.body = {
                    code:-1,
                    message:data
                }
            } else {
                ctx.body ={
                    code:1,
                    data
                }
            }
        } catch(err){
            ctx.body = {
                code:-1,
                message:err.message
            }
        }
    }
    async register() {
        const {ctx,app} = this;
        try{
            const data = await ctx.service.user.register()
            if(typeof data == 'string') {
                ctx.body = {
                    code:-1,
                    message:data
                }
            } else {
                ctx.body ={
                    code:1,
                    message:"注册成功"
                }
            }
        } catch(err){
            ctx.body = {
                code:-1,
                message:err.message
            }
        }
    }
}

module.exports = AddressController;
